const peMidoUrl = 'https://pixelexperience.org/mido'
describe('PE Download', () => {
  it('download', () => {
    cy.visit(peMidoUrl);
    let downloadUrl = '';
    /*
    cy.intercept('GET', 'https://download.pixelexperience.org/get/*', (req) => {
      downloadUrl = req.url
      req.reply({
        statusCode: 302,
        location: '/',
      })
    })
    */
    cy.get('body > main > div.device__info.wrap > div.device__downloads > div > div:nth-child(2)').click().then(() => {
      cy.get('body > main > div.device__info.wrap > div.device__downloads > div > div.accordion_tab.version__item.item__expanded > div > div > div.package__data > div:nth-child(2)').click().then(() => {
        cy.get('body > main > div.device__info.wrap > div.device__downloads > div > div.accordion_tab.version__item.item__expanded > div > div > div.package__data > div.accordion_tab.build__item.item__expanded > div > div.build__ddata > div > a').click().then(() => {
          cy.get('#swal2-content > a', { timeout: 10000 }).then(() => {
            const btn = Cypress.$('#swal2-content > a').first()
            downloadUrl = btn.get(0)['href']
            cy.downloadFile(downloadUrl, 'downloads', 'pe.zip')
            /*
            cy.request(downloadUrl).its('body').then((file) => {
              cy.writeFile('./cypress/downloads/pe.zip', file)
            })
            */
          })
        })
      });
    });
  })
})
